package com.example.myapplication.tack_30.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_30.data.AddressData;
import com.example.myapplication.tack_30.data.CommentData;
import com.example.myapplication.utils.OkHttpTool;
import com.google.gson.Gson;

import java.util.List;

public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.My> {
    private List<CommentData.RowsDTO> list;
    private Context context;
    private View view;

    public CommentAdapter(List<CommentData.RowsDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.tack_32_comment,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        if(!TextUtils.isEmpty(list.get(position).getUserName())){
            holder.name.setText(list.get(position).getUserName());
        }
        if(!TextUtils.isEmpty(list.get(position).getContent())){
            holder.content.setText(list.get(position).getContent());

        }
        if(!TextUtils.isEmpty(String.valueOf(list.get(position).getScore()))){
            holder.score.setText("评分"+list.get(position).getScore());
        }
        if(!TextUtils.isEmpty(list.get(position).getCommentDate())){
            holder.commentDate.setText(list.get(position).getCommentDate());

        }





    }

    @Override
    public int getItemCount() {
        return list != null?list.size():0;
    }

    public class My extends RecyclerView.ViewHolder{
        private ImageView avatar;
        private TextView name;
        private TextView content;
        private TextView score;
        private TextView commentDate;
        public My(@NonNull View itemView) {
            super(itemView);
            avatar = view.findViewById(R.id.avatar);
            name = view.findViewById(R.id.name);
            content = view.findViewById(R.id.content);
            score = view.findViewById(R.id.score);
            commentDate = view.findViewById(R.id.commentDate);
        }
    }
}
